package com.huahang.fashionpress.exception;

import com.huahang.fashionpress.config.ParamConfig;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;


/**
 * 全局异常处理控制
 * @author : 王翰聪 阿俊哥
 * @since : 2019/08/22
 * @version : 1.0
 */

@ControllerAdvice
public class ControllerException {

    @Resource
    ParamConfig paramConfig;

    @ExceptionHandler(value={ResultException.class})
    public String ExceptionError(ResultException e, Model model, HttpServletRequest request){
        String url = request.getRequestURL().toString();
        model.addAttribute("code", e.getCode());
        model.addAttribute("msg", e.getMessage());
        return "/admin/common/error";
    }

    @ExceptionHandler(AdminExecuteException.class)
    public ModelAndView AdminExceprion(){
        return new ModelAndView("redirect:/admin/" );
    }

    @ExceptionHandler(RoleException.class)
    public ModelAndView RoleException(){
        return new ModelAndView("/admin/common/norole");
    }

    @ExceptionHandler(NotloginException.class)
    public ModelAndView NotloginException(){
        return new ModelAndView("redirect:/login/" );
    }


}
